// TWExtAdfilter.h : Declaration of the CTWExtAdfilter

#ifndef __TWEXTADFILTER_H_
#define __TWEXTADFILTER_H_

#include "Res\resource.h"       // main symbols
#include <Exdisp.h>
#include <set>
#include <string>
#include "TWExtension.h"
using namespace std;

enum
{
	BS_ACTIVE=0,
	BS_SHOWN,
	BS_HIDDEN,
};

class CExtAdfilterObject :  public IObjectWithSite,
							public ITWExtBrowserEvent,
							public ITWExtMouseMessage,
							public ITWExtMsg
{
protected:
	DWORD m_ObjRefCount;
	IWebBrowser2 *m_pWebBrowser;
	IConnectionPoint *			m_pCP;
	IConnectionPointContainer * m_pCPC;
	DWORD						m_dwCookie;
public:
	TCHAR* GetUrl();
	CExtAdfilterObject();
	~CExtAdfilterObject();
	
	// IUnknown methods
	STDMETHODIMP QueryInterface(REFIID, LPVOID*);
	STDMETHODIMP_(DWORD) AddRef();
	STDMETHODIMP_(DWORD) Release();

	// IObjectWithSite methods
	STDMETHOD (SetSite) (IUnknown*);
	STDMETHOD (GetSite) (REFIID, LPVOID*);

	// ITWExtBrowserEvent
	STDMETHODIMP BrowserEventInvoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, 
					VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr, BOOL* pbHandled, DWORD dwBrowserState );
	STDMETHODIMP Active( DWORD dwActive );
	STDMETHODIMP OnRefresh( BOOL bComplete ){ return S_OK;};
	STDMETHODIMP OnExtMsg_NoUse( UINT uMsg, WPARAM wParam, LPARAM lParam ){return S_OK;};

	// ITWExtMouseMessage
	STDMETHODIMP MouseMessage( MSG* pMsg, BOOL* pbHandled );

	// ITWExtMsg
	STDMETHODIMP OnExtMsg( UINT uMsg, WPARAM wParam, LPARAM lParam );

public:
	void Reset( );
	BOOL	IsShown( );

	HWND		m_hBrowserWnd;

protected:
	HRESULT SendExtMessage( UINT uMsg, WPARAM wParam, LPARAM lParam );
	BOOL IsTopWebBrowser(IDispatch *pDisp);

protected:
	ITWExtBrowserHost*	m_pBrowserHost;

	DWORD		m_dwActive;
	TCHAR		m_szUrl[MAX_PATH];
};

#endif //__TWEXTADFILTER_H_
